﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using WpfSnqkGasAnalysis.IBusiness_impl;
using WpfSnqkGasAnalysis.Model;

namespace WpfSnqkGasAnalysis
{
    /// <summary>
    ///重置密码。 用户编辑弹出；
    /// </summary>
    /// 创建时间：2023-1-10 10:17:02；作者：王浩力
    public partial class WindowUserResetPassword : Window
    {
        public WindowUserResetPassword()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 选中的用户
        /// </summary>
        internal Login_user selectedUser;

        //登录密码修改
        private void btnConfirm_Click(object sender, RoutedEventArgs e)
        {
            if (selectedUser == null) {
                ShowAlertHelpter.ShowAlert("没有获取到修改用户");
                e.Handled = true;
                return;
            }
            if (string.IsNullOrWhiteSpace(this.txtNewPassword.Text.Trim()))
            {
                ShowAlertHelpter.ShowAlert("密码不可为空");
                e.Handled = true;
                return;
            }
            UserBusiness bll = new UserBusiness();
            //var user = GetLoginHelpter.CurrentLoginUser();
            Login_user user = selectedUser;
            string passNewHash = HashEncrypt.SHA256Encrypt(this.txtNewPassword.Text.Trim() + user.Password_salt);

            var result = bll.Update("password_hash", passNewHash, user.Id);
            ShowAlertHelpter.ShowAlert(result.Msg);
            if (result.CodeEnum==ResultCode.Success)
            {
                this.Close();
            }
        }
    }
}
